package com.foreknow.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.foreknow.config.CommonPage;
import com.foreknow.entity.Rule;
import com.foreknow.entity.Scheduling;
import com.foreknow.service.RuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@Api(tags = "RuleController",description = "排班规则管理")
@RestController
@RequestMapping("/rule")
public class RuleController {
    @Autowired
    private RuleService ruleService;

    @ApiOperation("查询排班规则")
    @PostMapping("/getRule")
    public CommonPage<Rule> getRule(Integer deptCategoryId, Integer deptId, Integer registLeId, Integer pageNum, Integer pageSize){
        List<Rule> List = ruleService.getRule(deptCategoryId,deptId,registLeId,pageNum,pageSize);
        return CommonPage.restPage(List);
    }


    @ApiOperation("新增排班规则")
    @PostMapping("/addRule")
    public int addRule(@RequestBody String ruleList){
        JSONObject jsonObject = JSONObject.parseObject(ruleList);
        List<Rule> list = JSONObject.parseArray(jsonObject.getJSONArray("ruleList").toJSONString(), Rule.class);
       return ruleService.addRule(list);
    }


    @ApiOperation("修改排班规则")
    @PostMapping("/updateRule")
    public int updateRule(String ruleName,Integer deptId,Integer userId,String week,Integer id){
        return ruleService.updateRule(ruleName,deptId,userId,week,id);
    }

    @ApiOperation("删除排班规则")
    @PostMapping("/deleteRule")
    public int deleteRule(Integer ruleId){
        return ruleService.deleteRule(ruleId);
    }
}
